#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <string.h>

int main(int argc, char *argv[])
{
	int lfd;
	struct sockaddr_in addr, caddr;
	socklen_t len = sizeof(caddr);
	char buf[BUFSIZ];
	char buf2[INET_ADDRSTRLEN];

	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(8080);
	addr.sin_addr.s_addr = htonl(INADDR_ANY);

	lfd = socket(AF_INET, SOCK_DGRAM, 0);
	
	bind(lfd, (struct sockaddr*)&addr, sizeof(addr));

	while(1)
	{
		int ret = recvfrom(lfd, buf, sizeof(buf), 0, (struct sockaddr*)&caddr, &len);
		printf("recvfrom %s port: %d\n ", inet_ntop(AF_INET,&caddr.sin_addr,buf2,sizeof(buf2)), ntohs(caddr.sin_port));
		sendto(lfd, buf, ret, 0, (struct sockaddr*)&caddr, len);
	}
	close(lfd);
	return 0;

}

